<!--学习驿站列表子项组件-->
<template>
  <view class="entire">
    <image :src="imageSrc" class="picture" mode="aspectFill" @error="handleImageError" />
    <view class="info">
      <view class="top">
        <view class="left">
          {{ knowledge.title }}
        </view>
      </view>
      <view class="bottom">
        <image
          style="width: 25rpx; height: 25rpx; margin-left: 10rpx"
          src="/static/images/icons/icon_time.png"
        />
        <view style="width: 250rpx; margin-left: 5rpx">
          {{ knowledge.endtime }}
        </view>
        <!-- todo 隐藏查看量 -->
        <!--        <image-->
        <!--          style="width: 25rpx; height: 25rpx; margin-left: 20rpx"-->
        <!--          src="/static/images/icons/icon_eye.png"-->
        <!--        />-->
        <!--        <view style="min-width: 50rpx; margin-left: 5rpx">{{ knowledge.look_num }}</view>-->
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { CollectionKnowledgeItem } from '@/service/collection/collection'
import { ref } from 'vue'

// 定义props，knowledge的类型为CollectionKnowledgeItem
const props = defineProps<{
  knowledge: CollectionKnowledgeItem
}>()

const defaultImage = '/static/images/icons/default.jpg'
const imageSrc = ref(props.knowledge.frontImg)

// 处理图片加载失败
const handleImageError = () => {
  imageSrc.value = defaultImage
}
</script>

<style scoped lang="scss">
.entire {
  width: 700rpx;
  height: 160rpx;
  background-color: white;
  border-radius: 15rpx;
  margin-left: 25rpx;
  margin-top: 30rpx;
  display: flex;
  .picture {
    width: 260rpx;
    height: 150rpx;
    margin-left: 5rpx;
    margin-top: 5rpx;
    border-radius: 15rpx;
  }
  .info {
    display: flex;
    width: 440rpx;
    height: 160rpx;
    flex-direction: column;
    justify-content: space-between;
    .top {
      display: flex;
      .left {
        font-size: 26rpx;
        padding-left: 20rpx;
        width: 340rpx;
        margin-top: 10rpx;
        font-weight: bold;
        //文字两行省略
        display: -webkit-box;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        white-space: normal;
        letter-spacing: 1rpx;
      }
      .right {
        width: 80rpx;
        height: 80rpx;
      }
    }
    .bottom {
      display: flex;
      height: 50rpx;
      align-items: center;
      font-size: 22rpx;
    }
  }
}
.entire:active {
  background-color: #f5f5f7;
}
</style>
